home *** CD-ROM | disk | FTP | other *** search
/ Amiga Plus 2002 #11 / Amiga Plus CD - 2002 - No. 11.iso / Tools / Development / TinyGL / ami / content / ad709 / tinygl / src / zline.c < prev    next >
Encoding:
C/C++ Source or Header  |  2002-08-15  |  2.1 KB  |  100 lines

  1. /*$T zline.c GC 1.137 08/09/02 17:47:18 */
  2.  
  3. /*$6
  4.  +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
  5.  +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
  6.  */
  7.  
  8. #include <stdlib.h>
  9. #include "zbuffer.h"
  10.  
  11. #define ZCMP(z, zpix)    ((z) >= (zpix))
  12.  
  13. /* */
  14.  
  15. void ZB_plot(ZBuffer *zb, ZBufferPoint *p) {
  16.     unsigned short    *pz;
  17.     PIXEL            *pp;
  18.     int                zz;
  19.     /*~~~~~~~~~~~~~~~~*/
  20.  
  21.     pz = zb->zbuf + (p->y * zb->xsize + p->x);
  22.     pp = (PIXEL *) ((char *) zb->pbuf + zb->linesize * p->y + p->x * PSZB);
  23.     zz = p->z >> ZB_POINT_Z_FRAC_BITS;
  24.     if(ZCMP(zz, *pz))
  25.     {
  26. #if TGL_FEATURE_RENDER_BITS == 24
  27.         pp[0] = p->r >> 8;
  28.         pp[1] = p->g >> 8;
  29.         pp[2] = p->b >> 8;
  30. #else
  31.         *pp = RGB_TO_PIXEL(p->r, p->g, p->b);
  32. #endif
  33.         *pz = zz;
  34.     }
  35. }
  36.  
  37. #define INTERP_Z
  38.  
  39. /* */
  40. static void ZB_line_flat_z(ZBuffer *zb, ZBufferPoint *p1, ZBufferPoint *p2, int color)
  41. {
  42. #include "zline.h"
  43. }
  44.  
  45. /* line with color interpolation */
  46. #define INTERP_Z
  47. #define INTERP_RGB
  48.  
  49. /* */
  50. static void ZB_line_interp_z(ZBuffer *zb, ZBufferPoint *p1, ZBufferPoint *p2)
  51. {
  52. #include "zline.h"
  53. }
  54.  
  55. /* no Z interpolation */
  56. static void ZB_line_flat(ZBuffer *zb, ZBufferPoint *p1, ZBufferPoint *p2, int color)
  57. {
  58. #include "zline.h"
  59. }
  60.  
  61. #define INTERP_RGB
  62.  
  63. /* */
  64. static void ZB_line_interp(ZBuffer *zb, ZBufferPoint *p1, ZBufferPoint *p2)
  65. {
  66. #include "zline.h"
  67. }
  68.  
  69. /* */
  70. void ZB_line_z(ZBuffer *zb, ZBufferPoint *p1, ZBufferPoint *p2) {
  71.     int color1, color2;
  72.  
  73.     color1 = RGB_TO_PIXEL(p1->r, p1->g, p1->b);
  74.     color2 = RGB_TO_PIXEL(p2->r, p2->g, p2->b);
  75.  
  76.     /* choose if the line should have its color interpolated or not */
  77.     if(color1 == color2) {
  78.         ZB_line_flat_z(zb, p1, p2, color1);
  79.     }
  80.     else {
  81.         ZB_line_interp_z(zb, p1, p2);
  82.     }
  83. }
  84.  
  85. /* */
  86. void ZB_line(ZBuffer *zb, ZBufferPoint *p1, ZBufferPoint *p2) {
  87.     int color1, color2;
  88.  
  89.     color1 = RGB_TO_PIXEL(p1->r, p1->g, p1->b);
  90.     color2 = RGB_TO_PIXEL(p2->r, p2->g, p2->b);
  91.  
  92.     /* choose if the line should have its color interpolated or not */
  93.     if(color1 == color2) {
  94.         ZB_line_flat(zb, p1, p2, color1);
  95.     }
  96.     else {
  97.         ZB_line_interp(zb, p1, p2);
  98.     }
  99. }
  100.